import java.util.*;

public class LandlordsSimulate_plus {
    //案例：模拟斗地主
    //需求：通过程序实现斗地主过程中的洗牌，发牌和看牌，能够实现对牌进行排序(通过TreeMap实现)
    public static void main(String[] args) {
        TreeMap<Integer,String> CardCase = new TreeMap<>();   //用于存放牌的大小顺序
        ArrayList<Integer> alt = new ArrayList<>();           //存放索引
        String[] color = {"♥","♠","♣","♦"};
        String[] number = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        int index = 0;
        for(String s1 : number)
            for(String s2 : color){
                alt.add(index);
                CardCase.put(index,s1 + s2);
                index++;
            }
        alt.add(index);
        CardCase.put(index++,"little Joker");
        alt.add(index);
        CardCase.put(index,"upper Joker");

        /*
        Set<Map.Entry<Integer, String>> entrySet = CardCase.entrySet();
        for(Map.Entry<Integer, String> me : entrySet)
            System.out.println(me.getKey() + " " + me.getValue());
         */

        //洗牌
        Collections.shuffle(alt);
        //发牌
        TreeSet<Integer> player1 = new TreeSet<>();
        TreeSet<Integer> player2 = new TreeSet<>();
        TreeSet<Integer> player3 = new TreeSet<>();
        TreeSet<Integer> basecard = new TreeSet<>();
     //   System.out.println(index + " " + alt.size() + " " + CardCase.size());
        for(int j = 0; j < alt.size();j++){
            int x = alt.get(j);
            if(j >= CardCase.size() - 3)
                basecard.add(x);
            else if(j % 3 == 0)
                player1.add(x);
            else if(j % 3 == 1)
                player2.add(x);
            else if(j % 3 == 2)
                player3.add(x);
            else
                System.out.println("出现错误！！！");
        }

        //看牌
        System.out.println("the base cards are : ");
        for(Integer s : basecard)
            System.out.print(CardCase.get(s) + " ");
        System.out.println();

        lookPoker("player1",player1,CardCase);
        lookPoker("player2",player2,CardCase);
        lookPoker("player3",player3,CardCase);

    }
    public static void lookPoker(String name,TreeSet<Integer> alt,Map<Integer,String> cardcase){
        System.out.println("The cards of " + name + " are : ");
        for(Integer i : alt)
            System.out.print(cardcase.get(i) + " ");
        System.out.println();
    }
}
